﻿using System.Text;
using Tilver.Coder.Utility;

namespace Tilver.Coder.Engine
{
    public class TableEngine : EngineBase ,ITableEngine
    {
        #region ITableEngine 成员

        public Core.CoderTable Table
        {
            get;
            set;
        }
        #endregion

        public override string RenderToString()
        {
            var response = new StringBuilder();
            ResponseClass(response, Tabs);
            return response.ToString();
        }

        private void ResponseClass(StringBuilder response, int tabs)
        {
            //输出引入命令空间
            base.ResponseNameSpaces(response, tabs);
            response.AppendLine();
            response.AppendFormatLine(tabs, "namespace {0}", NameSpace);
            response.AppendTabLine(tabs, "{");

            response.AppendTabLine(tabs + 1, "#region EO");
            response.AppendLine();
            #region 输出实体类
            var tableEOEngine = new TableEOEngine();
            tableEOEngine.DBTextStyle = DBTextStyle;
            tableEOEngine.NameSpace = NameSpace;
            tableEOEngine.Tabs = tabs + 1;
            tableEOEngine.Table = Table;
            response.AppendLine(tableEOEngine.RenderToString());
            #endregion
            response.AppendLine();
            response.AppendTabLine(tabs + 1, "#endregion");

            response.AppendTabLine(tabs + 1, "#region MO");
            response.AppendLine();
            #region 输出操作类
            var tableMOEngine = new TableMOEngine();
            tableMOEngine.DBTextStyle = DBTextStyle;
            tableMOEngine.NameSpace = NameSpace;
            tableMOEngine.Tabs = tabs + 1;
            tableMOEngine.Table = Table;
            response.AppendLine(tableMOEngine.RenderToString());
            #endregion
            response.AppendLine();
            response.AppendTabLine(tabs + 1, "#endregion");

            response.AppendTabLine(tabs, "}");
        }
    }
}
